define(function(require, exports, module) {
    'use strict';

    var $ = require('jquery');
    var io = require('plugins/request');
    var box = require('plugins/box/box');

    $('.jQuestion').click(function(){
    	var self = this,
    		val = $('.jAskIpt').val();
    	if(!val){
    		box.error('请输入问题！');
    		return false;
    	}
    	var data = {
    		data: val
    	}
    	getData(data, self);
    });

    //定时器每隔60s拉取一次回答数据
    setInterval(function(){
    	var data = {};
    	getData(data);
    }, 60000);

    function getData(data, self){
        io.jsonp('//life.com/json/problem.php', data, function(rst){
            var str = "";
            if(rst.data){
                if(rst.data.time){
                    str += '<div class="time-tag">'+ rst.data.time +'</div>';
                }
                str += rst.data.html;
                var $problem = $('.mod-problem');
                $problem.append(str).animate({
                    scrollTop: $problem[0].scrollHeight
                });
            }
        }, self);
    }

});
